package com.onepiece.im.test.ControllerTest

import com.liveinstars.api.im.FansApiService
import com.liveinstars.im.endpoint.FansApiEndPoint
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
import spock.lang.Unroll
import spock.mock.DetachedMockFactory

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get

@Slf4j
@WebMvcTest(FansApiEndPoint)
class FanControllerTest extends Specification {

    @Autowired MockMvc mockMvc

    @Autowired

    FansApiService fansApiService

    @Unroll
    def "url: /assign GET - #randomAdCache"() {
        given:
        log.debug("fansApiService: $fansApiService")

        when:
        def responseBody = mockMvc.perform(get("/fans")).andReturn().response.contentAsString
        log.debug("responseBody: $responseBody")
//        def extractedAd = objectMapper.readValue(responseBody, AvailableAdCache)

        then:
        responseBody == "22"



    }

    @TestConfiguration
    static class MockConfig {
        def detachedMockFactory = new DetachedMockFactory()

        @Bean
        FansApiService assignService() {
            return detachedMockFactory.Stub(FansApiService)
        }
    }
}
